var layer = layui.layer //弹层
    ,table = layui.table //表格
    ,form = layui.form,$ = layui.jquery,laydate = layui.laydate;

layui.use(['tableEdit',"excel"], function () {
    let tableEdit = layui.tableEdit;
    let layer = layui.layer,
        excel = layui.excel;

    lay('.starttime').each(function(){
        laydate.render({
            elem: this
        });
    });
//费用类型
    let allCost=[];
    layer.ready(function () {
//供应商
        $.ajax({
            url: "customer2/getAllInspectUnit",
            success: function (res) {
                if (res.status == 200) {
                    $.each(res.data, function (index, item) {
                        $("#supplierName").append(new Option(item.name, item.name));
                    });
                    form.render('select');
                } else {
                    layer.msg(res.msg, {icon: 5});
                }
            }
        });
    });
    form.render();//表单刷新
    let initData = [];
    table.render({
        elem: '#planInStoreSelect'
        ,data:initData
        ,toolbar: '#planInStoreToolbar'
        ,totalRow: true
        ,cols: [[
            ,{field: 'numbers',width: 50,type:'numbers',title:'序号', totalRowText: '合计'}
            ,{field:'billNo', title:'通知单号',sort:true,width: 120}
            ,{field:'createTimeStr', title:'创建日期',sort:true,width: 120}
            ,{field:'timeStr', title:'送仓日期',sort:true,width: 120}
            ,{field:'carryDetailTimeStr', title:'出运日期',sort:true,width: 120}
            ,{field:'productCode', title:'产品编码',sort:true,width: 120}
            ,{field:'specificationCode', title:'规格编码',sort:true,width: 120}
            ,{field:'specificationExplanation', title:'规格说明',sort:true,width: 120}
            ,{field:'productCname', title:'中文名称',sort:true,width: 120}
            ,{field:'lotNo', title:'批次',sort:true,width: 120}
            ,{field:'num', title:'通知数量',sort:true,width: 120, totalRow: true}
            ,{field:'productType', title:'产品类型',sort:true,width: 120}
            ,{field:'purchaseNo', title:'其他.采购单号',sort:true,width: 150}
            ,{field:'supplierName', title:'供应商',sort:true,width: 120}

            ,{field:'costUnitPrice', title:'成本单价',width: 120}
            ,{field:'costSubtotal', title:'成本小计',width: 120, totalRow: true}
            ,{field:'accessoriesCost', title:'配件成本',width: 120}
            ,{field:'finishedProductCost',title:'成品成本',sort:true,width: 120}
            ,{field:'price', title:'采购单价',width: 120}
            ,{field:'costPrice', title:'采购成本单价',width: 120}
            ,{field:'partsCostUnitPrice', title:'配件成本',width: 120}
            ,{field:'partsSupplierName', title:'配件供应商',width: 120}
            ,{field:'partsPurchaseNo', title:'配件采购单号',width: 120}

        ]]
        ,id: 'maininformationtableid'
        ,height: $(document).height() - $('#planInStoreSelect').offset().top - 75,
        //开启分页
        page: true,
        limits: [100,300,500],
    });


    //搜索提交
    form.on('submit(submitform)', function(data){
        data.field.source='export';//页面来源
        table.reload('maininformationtableid', {
            page: {
                limit:100,
                curr: 1
            },
            url:'planInStore/planInStoreStatistics1ListByPage',
            where:  data.field
        }, 'data');
        return false;
    });


    form.on('submit(exportData)', function (queryReq) {
        queryReq.field.source='export';//页面来源
        let index = layer.load(2, {
            shade: [0.4, '#000'],
            content: '加载中...',
            success: function (layero) {
                layero.find('.layui-layer-content').css({
                    'padding-top': '40px',
                    'width': '200px'
                });
            }
        });
        $.ajax({
            data: queryReq.field,
            url:"planInStore/planInStoreStatistics1Export",
            success: function(res) {
                if(res.status == 200){
                    //配置列宽
                    let colConf = excel.makeColConfig({
                        'A': 80,
                        'X': 80
                    }, 80);
                    excel.exportExcel({
                        sheet1: res.data.data
                    }, '新_入库通知统计.xlsx', 'xlsx', {
                        extend: {
                            '!cols': colConf
                        }
                    });
                }else {
                    layer.msg(res.msg, {icon: 5});
                }
                layer.close(index);
                return false;
            }
        });
        return false;
    });

});


